{% extends "manabe/template.html" %}
{% load static %}
{% block content %}
<div>
    <span class="l">
        {% if is_admin_group %}
            <a href="{% url 'appinput:create' %}" class="btn btn-primary radius">新建App应用</a>
        {% endif %}
    </span>
    <span class="select-box inline r">
        {% include "manabe/search.html" %}
    </span>
</div>
    <br>
    <br>

<table class="table table-border table-bordered table-bg">
    <thead>
    <th>App应用组件</th>
    <th>enkins job</th>
    <th>是否重启</th>
    <th>软件包名</th>
    <th>管理员</th>
    <th>编辑</th>
    <th>授权</th>
    <th>时间</th>
    </thead>
    <tbody>
    {% for item in object_list %}
    <tr class="text-l">
        <td>
            <span data-toggle="tooltip" data-placement="bottom" title="{{ item.description }}">
                <a href="{% url 'appinput:detail' pk=item.id %}">{{ item.name }}</a>
            </span>
        </td>
        <td>{{ item.jenkins_job }}</td>
        <td>{{ item.is_restart_status }}</td>
        <td>
            <span class="label label-primary radius">{{ item.package_name }}</span>
        </td>
        <td>{{ item.manage_user }}</td>
        <td>
            {% if is_admin_group %}
                <a href="{% url 'appinput:edit' pk=item.id %}">
                <button class="btn btn-warning-outline radius">编辑</button>
                </a>
            {% else %}
                {% ifequal request.user item.manage_user %}
                    <a href="{% url 'appinput:edit' pk=item.id %}">
                    <button class="btn btn-warning-outline radius">编辑</button>
                    </a>
                {% else %}
                    <button class="btn disabled radius">编辑</button>
                {% endifequal %}
            {% endif %}
        </td>
        <td>
            {% if is_admin_group %}
                <a href="{% url 'rightadmin:list' pk=item.id %}">
                <button class="btn btn-warning-outline radius">授权</button>
                </a>
            {% else %}
                {% ifequal request.user item.manage_user %}
                    <a href="{% url 'rightadmin:list' pk=item.id %}">
                    <button class="btn btn-warning-outline radius">授权</button>
                    </a>
                {% else %}
                    <button class="btn disabled radius">授权</button>
                {% endifequal %}
            {% endif %}
        </td>
        <td>{{ item.change_date }}</td>
    </tr>
    {% endfor %}
    </tbody>
</table>
    <br>
    {# pagination #}
<div class="text-r">
    <ul>
        {% if page_obj.has_previous %}
            <li>
                <a href="{{ current_url }}page={{ page_obj.previous_page_number }}" class="btn btn-primary-outline radius">上一页</a>
            </li>
        {% else %}
            <li>
                <a href="" class="btn btn-primary-outline radius">上一页</a>
            </li>
        {% endif %}
        <li>
            <a href="#"><span class="label label-primary radius">
                {{ page_obj.number }}/{{ page_obj.paginator.num_page }}
            </span></a>
        </li>
        {% if page_obj.has_next %}
        <li>
            <a href="{{ current_url }}page={{ page_obj.next_page_number }}" class="btn btn-primary-outline radius">
                下一页
            </a>
        </li>
        {% else %}
            <li>
                <a href="" class="btn btn-primary-outline radius">下一页</a>
            </li>
        {% endif %}
    </ul>
</div>
{% endblock %}

{% block script %}
<script>
$(".search_btn").click(function(){
    var search_pk = $("input[name='search_pk']").val() || "demo" ;
    if (search_pk === 'demo') {
        $.Huimodalalert('<span class="c-error">亲，请输入关键字再进行搜索</span>',3000);
        return false;
    }
    search_pk = search_pk.replace(/(^\s*)|(\s*$)/g, "");
    var url = "{% url 'appinput:list' %}?search_pk=" + search_pk
    console.log(url)
    location.href = url
});
</script>
{% endblock %}